/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package com.DAO;

import com.DAO.ConexaoPostgreSQL.ConnectionFactory;
import com.Model.ConfigFTP;
import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;

/**
 *
 * @author Fellipe
 */
public class ConfigFTPDAO {
    
    private Connection con = new ConnectionFactory().getConnection();
    private PreparedStatement pstm;
    
    public ConfigFTP read() {
    
        ConfigFTP ftp = new ConfigFTP();
        
        try {
            
            String sql = "SELECT * FROM configFTP";
            pstm = con.prepareStatement(sql);
            ResultSet rs = pstm.executeQuery();
            rs.next();

            ftp.setChaveConfig(rs.getInt("chaveConfig"));
            ftp.setEndereco(rs.getString("endereco"));
            ftp.setPorta(rs.getInt("porta"));
            ftp.setUsuario(rs.getString("usuario"));
            ftp.setSenha(rs.getString("senha"));
            ftp.setPastaDoc(rs.getString("pastaDoc"));
            ftp.setPastaImg(rs.getString("pastaDoc"));
            ftp.setPastaMult(rs.getString("pastaMult"));
            ftp.setPastaTemp(rs.getString("pastaTemp"));

        } catch (SQLException ex) {
            System.out.println(ex);
        } finally {
            try {
                pstm.close();
                con.close();
            } catch (SQLException ex) {
                System.out.println("Não foi possivel terminar a conexão " + ex);
            }
        }
        
        return ftp;
        
    }
    
    public ConfigFTP readUm(int chave) {
        
        ConfigFTP ftp = new ConfigFTP();
        
        try {
            
            String sql = "SELECT * FROM configFTP WHERE chaveConfig = ?";
            pstm = con.prepareStatement(sql);
            pstm.setInt(1, chave);
            ResultSet rs = pstm.executeQuery();
            rs.next();

            ftp.setChaveConfig(rs.getInt("chaveConfig"));
            ftp.setEndereco(rs.getString("endereco"));
            ftp.setPorta(rs.getInt("porta"));
            ftp.setUsuario(rs.getString("usuario"));
            ftp.setSenha(rs.getString("senha"));
            ftp.setPastaDoc(rs.getString("pastaDoc"));
            ftp.setPastaImg(rs.getString("pastaDoc"));
            ftp.setPastaMult(rs.getString("pastaMult"));
            ftp.setPastaTemp(rs.getString("pastaTemp"));

        } catch (SQLException ex) {
            System.out.println(ex);
        } finally {
            try {
                pstm.close();
                con.close();
            } catch (SQLException ex) {
                System.out.println("Não foi possivel terminar a conexão " + ex);
            }
        }
        
        return ftp;
        
    }
    
}
